<template>
    <el-drawer title="我是标题" :visible.sync="dialogVisible" :with-header="false" class="demand_box" size='600px' @close="closeGetData">
        <div class="flexbox flexcolumn height_100" v-loading="loading" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0)">
            <div class="demand_head flexbox flexcenter flexbetween">
                <span class="demand_title">添加UD短视频</span>
                <span class="icon_btn icon_btn_32"><img src="../../assets/img/close_check.svg" alt="" @click="closeGetData"></span>
            </div>
            <div class="pd_20 no_pb">
                <el-form label-position="top" style="margin-top:-10px" :model="queryInfo" size="medium" :hide-required-asterisk='true' ref="addForm" class="dialog_form">
                    <el-form-item label="选择品牌" prop="brand_id">
                        <el-form-item prop="brand_id" :rules="[{required:true, message: '请选择品牌',trigger: ['blur', 'change']}]">
                            <el-select v-model="queryInfo.brand_id" filterable placeholder="请选择品牌" style="width:100%">
                                <el-option :label="item.brand_name" :value="item.id" v-for="item in brandList" :key="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-form-item>
                </el-form>
                <div class="mt_20 font_14 color_01">日度消耗</div>
            </div>
            <div class="demand_center flex">
                <el-table :data="tableData" class="com_table" height="100%">
                    <div slot="empty" class="flexbox flexcenter flexcolumn flexjust" style="height:300px">
                        <img src="../../assets/img/null_icon.svg" alt="">
                        <div class="font_13 color_03">暂无数据</div>
                    </div>
                    <el-table-column prop="batch_num" label="日期" min-width="110">
                    </el-table-column>
                    <el-table-column prop="stat_cost" label="消耗" width="150">
                        <template slot-scope="scope">
                            <div class="flexbox flexcenter popper_hover">
                                {{scope.row.stat_cost?scope.row.stat_cost:0.00}}
                                <el-popover placement="top" width="160">
                                    <el-input v-model="scope.row.stat_cost" placeholder="" size="small"></el-input>
                                    <div style="text-align: right; margin-top: 10px">
                                        <el-button size="mini" type="text" @click="hidePop">取消</el-button>
                                        <el-button type="primary" size="mini" @click="editCost(scope.row)">确定</el-button>
                                    </div>
                                    <img src="../../assets/img/edit_icon2.svg" alt="" class="icon_btn icon_btn_width" slot="reference">
                                </el-popover>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
        </div>
    </el-drawer>
</template>

<script>
import monthdate from "../../assets/js/getmonth";
export default {
    name: "",
    data() {
        return {
            loading: false,
            dialogVisible: false,
            brandList: [],
            queryInfo: {
                year: this.$route.query.year,
                month: this.$route.query.month,
                author: this.$route.query.author,
                channel: 2,
                business_scene: 5,
                brand_id: "",
                stat_cost: "",
                batch_num: "",
            },
            tableData: [],
        };
    },
    created() {},
    methods: {
        //获取品牌列表
        async getBrandList() {
            const { data: res } = await this.$http.post(
                "launch/cost/brandListUd"
            );
            if (res.code !== 200) {
                this.$message.error(res.msg);
                return;
            } else {
                this.brandList = res.data.list;
            }
        },

        // 获取日期
        getTime(year, month) {
            this.tableData = [];
            let day = monthdate.currentMonthDays(year, month);
            for (let i in day) {
                this.tableData.push({
                    batch_num: day[i],
                    stat_cost: "0.00",
                });
            }
        },

        editCost(row) {
            this.$refs["addForm"].validate(async (valid) => {
                if (valid) {
                    this.loading = true;
                    this.queryInfo.batch_num = row.batch_num;
                    this.queryInfo.stat_cost = row.stat_cost;
                    const { data: res } = await this.$http.post(
                        "launch/cost/editCost",
                        this.queryInfo
                    );
                    if (res.code !== 200) {
                        this.loading = false;
                        this.$message.error(res.msg);
                        return;
                    } else {
                        this.loading = false;
                        this.hidePop();
                        this.$message({
                            message: "保存成功",
                            type: "success",
                        });
                        this.$emit("getDataList");
                    }
                } else {
                    return false;
                }
            });
        },

        hidePop() {
            document.body.click()
        },

        // 关闭详情
        closeGetData() {
            this.dialogVisible = false;
            this.$emit("getDataList");
        },
    },
    components: {},
};
</script>
<style scoped>
.step_box {
    height: 48px;
    background: rgba(165, 177, 209, 0.08);
    border-radius: 2px;
    padding: 0 20px;
    font-size: 14px;
    color: #616c85;
}
.step_box span {
    margin-left: 8px;
    color: #17233d;
}
.step_box .cost_number {
    font-family: D-DIN;
    font-weight: bold;
}
.no_pb {
    padding-bottom: 0;
}
.demand_center {
    padding-top: 12px;
}
</style>


